package com.ljh.ioc;

import com.ljh.ioc.controller.HelloController;
import com.ljh.ioc.model.Student;
import com.ljh.ioc.service.UserService;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;

@SpringBootApplication
public class SpringIocDemoApplication {

    public static void main(String[] args) {
        // ? 获取上下文
        ApplicationContext context = SpringApplication.run(SpringIocDemoApplication.class, args);

        // * 通过 bean 获取对象
//        HelloController bean1 = context.getBean(HelloController.class);
//        bean1.print();

        // * bean 里通过小驼峰命名类名 (返回的是 Object，需要强转)
//        HelloController bean2 = (HelloController) context.getBean("helloController");
//        bean2.print();

//        HelloController bean3 = context.getBean("helloController", HelloController.class);
//        bean3.print();

//        UserService bean1 = (UserService) context.getBean("userService");
//        bean1.print();
//
//        UserRepo bean2 = (UserRepo) context.getBean("userRepo");
//        bean2.print();
//
//        UserConfig bean3 = (UserConfig) context.getBean("userConfig");
//        bean3.print();
//
//        UserComponent bean4 = context.getBean(UserComponent.class);
//        bean4.print();

//        Student bean1 = (Student) context.getBean("s2");
//        System.out.println(bean1);

        UserService bean1 = context.getBean(UserService.class);
        bean1.print();
    }
}
